package com.teach.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.Random;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.teach.dto.User;

/**
 * <pre>
 * TODO : 控制器演示
 * - 移动端要调用的通常放api包下，pc端放web包下
 * ClassName : com.teach.controller.DemoController
 * Author : J.L.Zhou
 * Date : 2020-10-23 11:48
 * Version : V1.0
 * Copyright 2020 jlzhou.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes</pre>
 */
@Controller
// @RestController = @Controller + @ResponseBody
@RequestMapping("/demo")
public class DemoController {
	
	// /demo/demo-1.do
//	@RequestMapping("demo-1.do")
	@RequestMapping(value = "demo-1.do",method = {RequestMethod.GET,RequestMethod.POST})
	public String demo1(@RequestParam(defaultValue = "john")String name,Map<String, Object> attr) {
		attr.put("name", name);
		attr.put("list", Arrays.asList(1,2,3,4,5));
		return "demo-1";//返回的是视图名
	}
	
	@GetMapping("demo-2.do")
	@ResponseBody
	public User get(Long userId) {
		return new User(userId, "张三", new Random().nextBoolean(), new Date());
	}
}
